//
//  WYPusherController.m
//  CirclePush
//
//  Created by admin on 2018/4/18.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYPusherController.h"
#import "WYPusherHeaderCell.h"
#import "WYPusherCell.h"
#import "WYMyClueController.h"
#import "WYClueController.h"
#import "WYCommissionController.h"
#import "WYPusherMessageController.h"
#import "WYClewInfo.h"
#import "WYPusherInfpController.h"
@interface WYPusherController ()<UITableViewDelegate,UITableViewDataSource,WYPusherHeaderCellDelegate>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSArray *nameArray;
@property (nonatomic,strong)WYClewInfo *info;
@end

@implementation WYPusherController
-(NSArray *)nameArray
{
    if (!_nameArray) {
        _nameArray = @[@"新增线索",@"我的线索",@"我的提成"];
    }
    return _nameArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self loadData];
    
}
-(void)loadData
{
    WEAKSELF
    [WYHttpServer getClewInfoSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       
        if (success) {
            
            weakSelf.info = [WYClewInfo getClewInfoFromJson:response[@"result"]];
            [weakSelf.tableView reloadData];
            
        }else{
            [weakSelf toast:errorMessage];
        }
        
        
    }];
}
-(void)setupUI
{
    
    [self initTopBarWithTitle:@"我的推客主页"];
    [self addLeftButton:[UIImage imageNamed:@"return"] width:0 height:0];

    [self.view addSubview:self.tableView];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"WYPusherCell" bundle:nil] forCellReuseIdentifier:@"WYPusherCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"WYPusherHeaderCell" bundle:nil] forCellReuseIdentifier:@"WYPusherHeaderCell"];
    
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row==0) {
        WYPusherHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYPusherHeaderCell" forIndexPath:indexPath];
        if (!cell ) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"WYPusherHeaderCell" owner:nil options:nil].firstObject;
        }
        cell.delegate = self;
        [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
        if (self.info) {
            [cell setInfo:self.info];
        }
        
        
        return cell;
    }
    
    WYPusherCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYPusherCell" forIndexPath:indexPath];
    if (!cell ) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"WYPusherCell" owner:nil options:nil].firstObject;
    }
    cell.pusherName.text = self.nameArray[indexPath.row-1];
    [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
    return cell;
    
    
    
    
    
    return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==1) {
        WYClueController *Cvc= [[WYClueController alloc]init];
        [self.navigationController pushViewController:Cvc animated:YES];
    }
    if (indexPath.row==2) {
        WYMyClueController *mvc = [[WYMyClueController alloc]init];
        [self.navigationController pushViewController:mvc animated:YES];
    }
    if (indexPath.row==3) {
        WYCommissionController *cvc= [[WYCommissionController alloc]init];
        //
        if ([_info.count objectForKey:@"commission"]) {
            cvc.price = self.info.count[@"commission"];
        }else{
            // self.orderPrice.text = @"0.00";
            cvc.price = @"0";
            
        }
        
        [self.navigationController pushViewController:cvc animated:YES];
    }
//    if (indexPath.row==4) {
//        WYPusherMessageController *PVC= [[WYPusherMessageController alloc]init];
//        [self.navigationController pushViewController:PVC animated:YES];
//    }
}

-(void)clickExtractAction
{
    WYCommissionController *cvc= [[WYCommissionController alloc]init];
    //
    if ([_info.count objectForKey:@"commission"]) {
        cvc.price = self.info.count[@"commission"];
    }else{
        // self.orderPrice.text = @"0.00";
        cvc.price = @"0";
        
    }
    
    [self.navigationController pushViewController:cvc animated:YES];
}
-(void)clickUserImageView
{
    NSLog(@"11111111111");
    
    WYPusherInfpController *pic = [[WYPusherInfpController alloc]init];
    pic.clew = self.info;
    [self.navigationController pushViewController:pic animated:YES];
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        return 240;
    }
    return 44;
}



-(UITableView *)tableView
{
    
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.frame = CGRectMake(0, NavHeight, kScreenWidth, kScreenHeight);
        _tableView.tableFooterView = [[UIView alloc]init];
    }
    return _tableView;
    
    
    
    
    
    
}

@end
